# 作者：20242321汤泽鹏
# 地点：电科院
# 时间：4 a.m
# 代理地址：Los Angels

from cryptography.fernet import Fernet
import socket

with open('secret.key', 'rb') as key_file:
    key = key_file.read()
cipher = Fernet(key)

def send_file(client_filename):
    with open(client_filename, 'rb') as file:
        original_file = file.read()
    encrypted_data = cipher.encrypt(original_file)

    client_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    client_socket.connect(('192.168.43.59', 8080))
    client_socket.send(encrypted_data)
    print("文件已加密发送")
    client_socket.close()

while True:
    client_input = input("是否要发送文件Y/n:")
    if client_input in ('Y', 'y'):
        client_filename = input("请输入要发送的文件名")
        send_file(client_filename)
    elif client_input in ('N', 'n'):
        print('''结束文件传输。
感谢使用。''')
        break
    else:
        print("输入无效，请输入Y/n")